# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : AdaBoost-评估葡萄酒质量.py
# @Author: dongguangwen
# @Date  : 2025-02-08 15:15
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.ensemble import AdaBoostClassifier
from sklearn.metrics import accuracy_score


data = pd.read_csv('./data/wine0501.csv')
# print(data.head())
# print(data.info())

data = data[data['Class label'] != 1]
# print(data.info())
x = data[['Alcohol', 'Hue']].copy()
y = data['Class label'].copy()
# print(y)

pre = LabelEncoder()  # 类别转化 (2,3)=>(0,1)
y = pre.fit_transform(y)
# print(y)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=22)

# 模型训练1
ada = AdaBoostClassifier()
ada.fit(x_train, y_train)


print(ada.score(x_test, y_test))
y_pred = ada.predict(x_test)
print(accuracy_score(y_test, y_pred))

"""
0.9583333333333334
0.9583333333333334
"""